package net.zzy.pbbot.plugin.music.service;

import com.alibaba.fastjson.JSON;
import lombok.SneakyThrows;
import net.lz1998.pbbot.utils.Msg;
import net.zzy.pbbot.plugin.music.entity.MusicResp;
import net.zzy.pbbot.util.HttpsUtils;
import org.springframework.stereotype.Component;

import static net.zzy.pbbot.finalfield.Api.MUSIC_URL;

/**
 * @author zhuZhaoYang
 * @date 2021/9/24 16:46
 */
@Component
public class MusicService {

    @SneakyThrows
    public static Msg getMusic(String[] messages) {
        if (messages.length < 2) {
            return Msg.builder().text("请以\"点歌 歌名\"格式发送");
        }
        String resp = HttpsUtils.get(MUSIC_URL + messages[1], null, null);
        MusicResp musicResp = JSON.parseObject("{" + resp + "}", MusicResp.class);
        return Msg.builder().json((int) System.currentTimeMillis(), musicResp.getJson());
    }
}
